package com.example.rightmost.controller.user;

import com.example.rightmost.entity.*;
import com.example.rightmost.service.CommentService;
import com.example.rightmost.service.PieceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author:javayhch
 * @date:2024/8/20
 * @description:
 */

@RestController
@RequestMapping("/user/piece")
public class PieceController {

    @Autowired
    public PieceService pieceService;

    @Autowired
    public CommentService commentService;

    @RequestMapping("/getPieces")
    public List<Piece> getPieces(){
        return pieceService.getPieces();
    }

    @RequestMapping("/getUserNameMap")
    public Result getUserNameMap(){
        return pieceService.getUserNameMap();
    }

    @RequestMapping("/getUserAvatarMap")
    public Result getUserAvatarMap(){
        return pieceService.getUserAvatarMap();
    }

    @RequestMapping("/getTopicNameMap")
    public Result getTopicNameMap(){
        return pieceService.getTopicNameMap();
    }

    @RequestMapping("/doWells")
    public Result doWells(@RequestParam int pieceId,
                          @RequestParam int num
    ){
        return pieceService.doWells(pieceId, num);
    }

    @RequestMapping("/addPiece")
    public Result addTopic(@RequestBody Piece piece){
        return pieceService.addPiece(piece);
    }

    @RequestMapping("/getPiecesById")
    public List<Piece> getPiecesById(@RequestParam int id){
        List<Piece> list = pieceService.getPiecesById(id);
        return list;
    }

    @RequestMapping("/getPieceById")
    public Piece getPieceById(@RequestParam int pieceId) {
        return pieceService.getPieceById(pieceId);
    }

    @RequestMapping("/getCommentArea")
    public List<Comment> getCommentArea(@RequestBody Comment comment) {
        List<Comment> list = commentService.getCommentArea(comment);
        return list;
    }

    @RequestMapping("/getCommentSon")
    public Map<Integer, List<Comment>> getCommentSon(@RequestParam int pieceId) {
        return commentService.getCommentSon(pieceId);
    }

    @RequestMapping("/addComment")
    public Result addComment(@RequestBody Comment comment) {
        return commentService.addComment(comment);
    }

    @RequestMapping("/addComment_2")
    public Result addComment_2(@RequestBody Comment comment) {
        return commentService.addComment_2(comment);
    }

    @RequestMapping("/getLikeInfo")
    public Result getLikeInfo(@RequestParam int creationId, @RequestParam int userId) {
        return pieceService.getLikeInfo(creationId, userId);
    }

    @RequestMapping("/doLike")
    public Result doLike(@RequestBody PieceLike pieceLike) {
        return pieceService.doLike(pieceLike);
    }

    @RequestMapping("/noLike")
    public Result noLike(@RequestBody PieceLike pieceLike) {
        return pieceService.noLike(pieceLike);
    }

    @RequestMapping("/getUserMap")
    public Map<Integer, User> getUserMap(){
        return pieceService.getUserMap();
    }

    @RequestMapping("/delete")
    public Result delete(@RequestParam int commentId) {
        return commentService.delete(commentId);
    }

}
